﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

namespace App1.DataModel
{
     public class GroupEvent:App1.Common.BindableBase {

        private string _uniqueId = string.Empty;
        private string _title = string.Empty;
        private string _subtitle = string.Empty;
        private string _description = string.Empty;
        // private ImageSource _image = null;
        private String _imagePath = null;
        public List<Event> Events = new List<Event>();


        public GroupEvent(String uniqueId, String title, String subtitle, String imagePath, String description)
        {
            this._uniqueId = uniqueId;
            this._title = title;
            this._subtitle = subtitle;
            this._description = description;
            this._imagePath = imagePath;

        }

        public string UniqueId
        {
            get { return this._uniqueId; }
            set { this.SetProperty(ref this._uniqueId, value); }
        }
     }

    public class Event:App1.Common.BindableBase
    {
        public List<Tag> _channels = new List<Tag>();
        private static Uri _baseUri = new Uri("ms-appx:///");
        private string _uniqueId = string.Empty;
        private string _title = string.Empty;
        private string _subtitle = string.Empty;
        private string _description = string.Empty;
        private ImageSource _image = null;
        private String _imagePath = null;
        private GroupEvent _group;

        public Event(String uniqueId, String title, String subtitle, String imagePath, String description, List<Tag> channels, GroupEvent group)
        {
            this._uniqueId = uniqueId;
            this._title = title;
            this._subtitle = subtitle;
            this._description = description;
            this._imagePath = imagePath;
            this._channels = channels; // POSSIBLE ERROR DE ALIASING
            this._group = group;
        }

        public string UniqueId {
            get { return this._uniqueId; }
            set { this.SetProperty(ref this._uniqueId, value); }
        }

        private Double latitude;
        public Double Latitude
        {
            get { return this.latitude; }
            set { this.latitude = value; }
        }

        private Double longitude;
        public Double Longitude
        {
            get { return this.longitude; }
            set { this.longitude = value; }
        }

        public string Title
        {
            get { return this._title; }
            set { this.SetProperty(ref this._title, value); }
        }

        public GroupEvent Group
        {
            get { return this._group; }
            set { this.SetProperty(ref this._group, value); }
        }
        
        public string Subtitle
        {
            get { return this._subtitle; }
            set { this.SetProperty(ref this._subtitle, value); }
        }


        public List<Tag> Channels
        {
            get { return this._channels; }
            set { this.SetProperty(ref this._channels, value); }
        }

        public void addChannel(Tag channel) {
            _channels.Add(channel);
        }

        public string Description
        {
            get { return this._description; }
            set { this.SetProperty(ref this._description, value); }
        }

        public ImageSource Image {
            get {
                if (this._image == null && this._imagePath != null) {
                    this._image = new BitmapImage(new Uri(Event._baseUri, this._imagePath));
                }
                return this._image;
            }
            set {
                this._imagePath = null;
                this.SetProperty(ref this._image, value);
            }
        }

        public void SetImage(String path) {
            this._image = null;
            this._imagePath = path;
            this.OnPropertyChanged("Image");
        }
    }
}
